//
// CrackPluginBuild
//
// Copyright (C) jextra.net.
//
//  This file is part of the Crack build system.
//
//  The Crack build system is free software; you can redistribute it 
//  and/or modify it under the terms of the GNU Lesser General Public
//  License as published by the Free Software Foundation; either
//  version 2.1 of the License, or (at your option) any later version.
//
//  The Crack build system is distributed in the hope that it will be 
//  useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
//  Lesser General Public License for more details.
//
//  You should have received a copy of the GNU Lesser General Public
//  License along with the Crack build system; if not, write to the Free
//  Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
//  02111-1307 USA.
//

package net.jextra.crack.plugindev;

import java.io.*;
import java.util.*;
import net.jextra.crack.*;
import net.jextra.crack.java.*;

/**
 * <p>
 * A build file base class for developing a Crack plugin. It is more than likely that this will
 * be the Build file you extend in your Build.crack file if you are developing a plugin to
 * Crack. The most basic example is:
 * </p>
 * <pre>
 * package com.mycompany.crackplugin;
 * 
 * import net.jextra.crack.build.*;
 * 
 * public class Build extends CrackPluginBuild
 * {
 *     ...
 * }
 * </pre>
 */
public abstract class CrackPluginBuild extends CrackBuild
{
    // ============================================================
    // Fields
    // ============================================================

    private CrackPluginBuildParams params;

    // ============================================================
    // Constructors
    // ============================================================

    public CrackPluginBuild()
    {
        try
        {
            params = new CrackPluginBuildParams();

            // Add basic java compiling knob.
            JavaKnob javaKnob = new JavaKnob( params );
            addCommands( javaKnob );

            // Add plugin specifc knob.
            CrackPluginKnob pluginKnob = new CrackPluginKnob( params );
            addCommands( pluginKnob );
        }
        catch ( Exception ex )
        {
            throw new CrackException( ex );
        }
    }

    // ============================================================
    // Methods
    // ============================================================

    // ----------
    // public
    // ----------

    public abstract String getBuildName();

    public abstract Collection<File> getDependencies();

    // ----------
    // protected
    // ----------

    protected CrackPluginBuildParams getParams()
    {
        return params;
    }

    // ============================================================
    // Inner Classes
    // ============================================================

    protected class CrackPluginBuildParams extends Convention1JavaParams implements JavaKnobParams,
        CrackPluginKnobParams
    {
        @Override
        public String getBuildName()
        {
            return CrackPluginBuild.this.getBuildName();
        }

        @Override
        public Collection<File> getDependencies( String... scopes )
        {
            return CrackPluginBuild.this.getDependencies();
        }
    }
}
